#include <iostream>
#include <unistd.h>
#include <csignal>
#include <sys/types.h>

using namespace std;

void handle_alarm(int sig)
{
    cout << "[Main] Received SIGALRM (" << sig << "): timeout triggered.\n";
}

void handle_usr1(int sig)
{
    cout << "[Main] Received SIGUSR1 (" << sig << "): child pinged me.\n";
}

int main()
{
    signal(SIGALRM, handle_alarm);
    signal(SIGUSR1, handle_usr1);

    pid_t pid = fork();
    if(pid == 0)
    {
        sleep(1);
        kill(getppid(), SIGUSR1);
        return 0;
    }

    alarm(3);
    for(int i = 0; i < 2; i++)
    {
        pause();
    }
    cout << "[Main] Done." << endl;
    return 0;
}
